<template>
    <div>
        <el-table
                stripe
                :data="orderList"
                style="width: 100%">
            <el-table-column
                    align="center"
                    label="订单编号"
                    prop="orderno">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="下单用户"
                    prop="username">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="订单状态"
                    prop="status">
                <template  slot-scope="scope">
                    <span v-if="scope.row.status==1"><el-tag>待接单</el-tag></span>
                    <span v-if="scope.row.status==2"><el-tag type="info">待完成</el-tag></span>
                    <span v-if="scope.row.status==3 || scope.row.status==4"><el-tag type="success">已完成</el-tag></span>
                    <span v-if="scope.row.status==4"><el-tag type="warning">待评价</el-tag></span>
                    <span v-if="scope.row.status==5"><el-tag type="danger">已失效</el-tag></span>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    label="接单员工"
                    prop="emp">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="员工电话"
                    prop="empTel">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="实际付款"
                    prop="orderPrice">
            </el-table-column>

            <el-table-column label="操作" align="center" width="180">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            type="primary"
                            @click="orderDetail( scope.row)">详情
                    </el-button>
                    <el-button
                            size="mini"
                            type="danger"
                            @click="deleteOrder( scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                :page-size="7"
                :pager-count="5"
                @current-change="getOrderByPage"
                layout="prev, pager, next"
                :total="totalOrder">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                orderList:[],     //分页获取的订单列表
                totalOrder:null,   //分页总条数
                tempEmp:'',

            };
        },
        created() {
            this.getOrderByPage(1);
        },
        methods: {


            getOrderByPage(currentPage){
                var that=this;
                this.$ajax.post('/jz/order/showOrderByPage?currentPage='+currentPage).then(function (resp) {
                    console.log(resp.data);
                    if(resp.data.status==200){
                        that.totalOrder=resp.data.totalCount;
                        that.orderList=resp.data.orderList;
                    }
                    if(resp.data.status==204){
                        that.$message.error('没有订单');
                    }
                })
            },

            orderDetail(row){
                //console.log(row.id)
                this.$router.push({
                    path: '/orderDetail',
                    query:{
                        oid:row.id
                    }
                })
            },

            deleteOrder(row) {
                console.log( row);
                this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var that=this;
                    this.$ajax.post('/jz/order/deleteOrderById?id='+row.id).then(function (resp) {
                        //console.log(resp.data);
                        if(resp.data.status==200){
                            that.$message({
                                message: '删除成功，请刷新！',
                                type: 'success'
                            });
                        }
                        if(resp.data.status==204){
                            that.$message.error('删除失败，请重试！');
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        },
        // mounted() {
        //     this.loadAll();
        // }
    }
</script>

<style scoped>

</style>
